package mysql;

import com.google.common.base.Joiner;
import mysql.types.Type;

/**
 * Created by nuno-rafael-figueiredo on 02-07-2014.
 */
public class ColumnDefinition {

    private String name;
    private final Type type;
    private boolean notNull;
    private boolean primary;

    public ColumnDefinition(String name, Type type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "\t" + Joiner
                        .on(" ")
                        .skipNulls()
                        .join(
                                MySQL.wrap(name),
                                type,
                                notNull ? "NOT NULL": null
                        );
    }

    public ColumnDefinition notNull(boolean notNull) {
        this.notNull = notNull;
        return this;
    }

    public boolean primary() {
        return primary;
    }

    public ColumnDefinition primary(boolean primary) {
        this.primary = primary;
        return this;
    }
}
